<template>
  <n-layout-footer bordered class="footer">
    <div class="footer-content">
      <div class="footer-section">
        <n-text class="footer-title" strong>
          {{ blogConfig?.blogName || '我的博客' }}
        </n-text>
        <n-text class="footer-desc" depth="3">
          {{ blogConfig?.personalSay || '分享技术，记录生活' }}
        </n-text>
      </div>

      <div class="footer-section">
        <n-text class="footer-title" strong>联系方式</n-text>
        <n-space vertical size="small">
          <div v-if="blogConfig?.qqLink" class="contact-item">
            <n-text depth="3">QQ:</n-text>
            <n-image
              :src="blogConfig.qqLink"
              :alt="'QQ二维码'"
              width="80"
              height="80"
              object-fit="cover"
              preview-disabled
            />
          </div>
          <div v-if="blogConfig?.wechatLink" class="contact-item">
            <n-text depth="3">微信:</n-text>
            <n-image
              :src="blogConfig.wechatLink"
              :alt="'微信二维码'"
              width="80"
              height="80"
              object-fit="cover"
              preview-disabled
            />
          </div>
          <div v-if="blogConfig?.githubLink" class="contact-item">
            <n-text depth="3">GitHub:</n-text>
            <n-text depth="3" class="github-link">
              <a :href="blogConfig.githubLink" target="_blank" rel="noopener noreferrer">
                {{ blogConfig.githubLink }}
              </a>
            </n-text>
          </div>
        </n-space>
      </div>

      <div class="footer-section">
        <n-text class="footer-title" strong>统计信息</n-text>
        <n-text depth="3">
          访问量: {{ blogConfig?.viewCount || 0 }}
        </n-text>
      </div>
    </div>

    <div class="footer-bottom">
      <n-space vertical size="small" align="center">
        <n-text depth="3">
          © {{ new Date().getFullYear() }} {{ blogConfig?.blogName || '我的博客' }}. All rights reserved.
        </n-text>
        <n-text depth="3">
          <a href="https://beian.miit.gov.cn/" target="_blank" rel="noopener noreferrer" class="beian-link">
            湘ICP备2023014074号-1
          </a>
        </n-text>
      </n-space>
    </div>
  </n-layout-footer>
</template>

<script setup lang="ts">
import { computed, onMounted } from 'vue'
import { useUserStore } from '@/stores/user'

const userStore = useUserStore()

const blogConfig = computed(() => userStore.blogConfig)

onMounted(async () => {
  if (!blogConfig.value) {
    await userStore.fetchBlogConfig()
  }
})
</script>

<style scoped>
.footer {
  background: #f5f5f5;
  padding: 40px 24px 20px;
}

.footer-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 40px;
  margin-bottom: 30px;
}

.footer-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.footer-title {
  font-size: 16px;
  margin-bottom: 8px;
}

.footer-desc {
  line-height: 1.6;
}

.contact-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.github-link a {
  color: inherit;
  text-decoration: none;
  word-break: break-all;
}

.github-link a:hover {
  text-decoration: underline;
}

.footer-bottom {
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid #e0e0e0;
}

.beian-link {
  color: inherit;
  text-decoration: none;
}

.beian-link:hover {
  text-decoration: underline;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .footer {
    padding: 30px 16px 15px;
  }

  .footer-content {
    grid-template-columns: 1fr;
    gap: 30px;
  }

  .contact-item {
    align-items: center;
  }
}
</style>
